<?php
namespace app\common\lib\user_operate;

use app\common\lib\Common;
use app\common\lib\EntranceToken as ET;

/**
 * 插件操作
 */
class PluginOperate
{

    public function __construct()
    {
        $this->common = new Common;

    }

    /**
     * 插件列表
     */
    public function getPluginList($store_id = '')
    {

        $data = [
            'token' => ET::getToken(),
            'param' => [
                'type'     => '2020062813',
                'store_id' => $store_id,
            ],

        ];
        $res = $this->common->requestInterface(ET::getUrl(), $data);

        return $res;
    }

    /**
     * 下载链接
     */
    public function getDownloadUrl($p_id)
    {

        $data = [
            'token' => ET::getToken(),
            'param' => [
                'type' => '2020062812',
                'p_id' => $p_id,
            ],

        ];
        $res = $this->common->requestInterface(ET::getUrl(), $data);

        if (isset($res['data']) && !empty($res['data'])) {
            $res['data'] = urldecode($res['data']);
        }

        return $res;
    }

    /**
     * 获取安装状态
     */
    public function isInstall($module_name, $plugin_name)
    {
        //判断是否存在安装日志文件
        $dir = ROOT_PATH . '/public/plugins/' . cmf_parse_name($module_name);

        $dir .= '/config/install/' . cmf_parse_name($plugin_name) . '.log';

        if (file_exists($dir)) {
            return true;
        } else {
            return false;
        }
    }

}
